# 所有和数据库有关的函数方法
import pymysql
# 定义和数据库的连接
conn = pymysql.connect(
    host="localhost",
    port=3306,
    user="root",
    passwd="root",
    db="assistant",
    charset='utf8',
    cursorclass=pymysql.cursors.DictCursor
)

# 根据用户名查询用户是否存在的函数
def query_user_no_exists(username):
    sql = "select * from sys_user where username = %s"
    cur = conn.cursor()
    cur.execute(sql, [username])
    result = cur.fetchone()
    if result is None:
        return True
    else:
        return False

# 根据用户名和密码添加数据的函数
def add_user(username,password):
    sql = "insert into sys_user (username,password) values (%s,%s)"
    cur = conn.cursor()
    cur.execute(sql, [username,password])
    conn.commit()
